import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class CollectionsTest1 {
/*
    掌握Collections集合工具类的使用
 */

    public static void main(String[] args) {
        // Colltections.addAll    为集合批量添加数据
        List<String> names = new ArrayList<>();
        Collections.addAll(names,"张三","李四","王五","赵六","田七");
        System.out.println(names);

        // Collections.shuffle    打乱list集合中的元素顺序
        Collections.shuffle(names);
        System.out.println(names);

        // Collections.sort       对List集合中的元素进行升序排序
        List<Integer> nums = new ArrayList<>();
        Collections.addAll(nums,6,3,9,5,2);
        Collections.sort(nums);
        System.out.println(nums);

        // 对List集合中的元素，按照比较器对象指定的规则进行排序
        List<Studnet> studnets = new ArrayList<>();
        studnets.add(new Studnet("张三",183.5,18));
        studnets.add(new Studnet("李四",175.5,38));
        studnets.add(new Studnet("王五",189.5,25));
        studnets.add(new Studnet("赵六",164.5,20));
        Collections.sort(studnets, new Comparator<Studnet>() {
            @Override
            public int compare(Studnet o1, Studnet o2) {
                return Double.compare(o1.getHeight(),o2.getHeight());
            }
        });
        System.out.println(studnets.toString());
    }
}
